#include "InetAddr.h"
#include <iostream>

using std::cout;
using std::endl;

#include <string.h>
InetAddr::InetAddr(const string &ip, unsigned short port)
{
    memset(&_addr, 0, sizeof(_addr));
    _addr.sin_family = AF_INET;
    _addr.sin_port = htons(port);
    _addr.sin_addr.s_addr = inet_addr(ip.c_str());
}
InetAddr::InetAddr(const struct sockaddr_in & addr)
: _addr(addr){}

InetAddr::~InetAddr()
{

}

string InetAddr::ip() const
{
    return string(inet_ntoa(_addr.sin_addr));
}

unsigned short InetAddr::port() const
{
    return ntohs(_addr.sin_port);
}

struct sockaddr_in *InetAddr::getAddrPtr()
{
    return &_addr;
}

